package lichunUtil;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.PrintStream;

public class SimRecord {
	static public void writeDoubleTrix (double[][][] mat, String file) {
		try {
			PrintStream ps = new PrintStream(file);
			ps.println(mat.length);
			for (int i=0;i<mat.length;i++) {
				ps.println(mat[i].length);
				for (int j=0;j<mat[i].length;j++) {
					ps.println(mat[i][j].length);
					for (int k=0;k<mat[i][j].length;k++) {
						ps.println(mat[i][j][k]);
					}
				}
			}
			ps.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	static public void writeDoubleMatrix (double[][] mat, String file) {
		try {
			PrintStream ps = new PrintStream(file);
			ps.println(mat.length);
			for (int i=0;i<mat.length;i++) {
				ps.println(mat[i].length);
				for (int j=0;j<mat[i].length;j++) {
					ps.println(mat[i][j]);
				}
			}
			ps.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	static public double[][][] readDoubleTrix (String file) {
		double[][][] res = null;
		try {
			BufferedReader br = new BufferedReader(new FileReader(file));
			int len = Integer.parseInt(br.readLine());
			res = new double[len][][];
			for (int i=0;i<len;i++) {
				int plen = Integer.parseInt(br.readLine());
				res[i] = new double[plen][];
				for (int j=0;j<res[i].length;j++) {
					int klen = Integer.parseInt(br.readLine());
					res[i][j] = new double[klen];
					for (int k=0;k<res[i][j].length;k++) {
						res[i][j][k] = Double.parseDouble(br.readLine());
					}
				}
			}
			br.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}
		return res;
	}
	
	static public double[][] readDoubleMatrix (String file) {
		double[][] res = null;
		try {
			BufferedReader br = new BufferedReader(new FileReader(file));
			int len = Integer.parseInt(br.readLine());
			res = new double[len][];
			for (int i=0;i<len;i++) {
				int plen = Integer.parseInt(br.readLine());
				res[i] = new double[plen];
				for (int j=0;j<res[i].length;j++)
					res[i][j] = Double.parseDouble(br.readLine());
			}
			br.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}
		return res;
	}
	
	static public void writeIntMatrix (int[][] mat, String file) {
		try {
			PrintStream ps = new PrintStream(file);
			ps.println(mat.length);
			for (int i=0;i<mat.length;i++) {
				ps.println(mat[i].length);
				for (int j=0;j<mat[i].length;j++) {
					ps.println(mat[i][j]);
				}
			}
			ps.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	static public int[][] readIntMatrix (String file) {
		int[][] res = null;
		try {
			BufferedReader br = new BufferedReader(new FileReader(file));
			int len = Integer.parseInt(br.readLine());
			res = new int[len][];
			for (int i=0;i<len;i++) {
				int plen = Integer.parseInt(br.readLine());
				res[i] = new int[plen];
				for (int j=0;j<res[i].length;j++)
					res[i][j] = Integer.parseInt(br.readLine());
			}
			br.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}
		return res;
	}
	
	static public void writeIntArray(int[] x, String file) {
		try {
			PrintStream ps = new PrintStream(file);
			ps.println(x.length);
			for (int i=0;i<x.length;i++)
				ps.println(x[i]);
			ps.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	static public int[] readIntArray(String file) {
		int[] res = null;
		try {
			BufferedReader br = new BufferedReader(new FileReader(file));
			int len = Integer.parseInt(br.readLine());
			res = new int[len];
			for (int i=0;i<len;i++) 
				res[i] = Integer.parseInt(br.readLine());
			br.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}
		return res;
	}
	static public void writeDoubleArray(double[] x, String file) {
		try {
			PrintStream ps = new PrintStream(file);
			ps.println(x.length);
			for (int i=0;i<x.length;i++)
				ps.println(x[i]);
			ps.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	static public double[] readDoubleArray(String file) {
		double[] res = null;
		try {
			BufferedReader br = new BufferedReader(new FileReader(file));
			int len = Integer.parseInt(br.readLine());
			res = new double[len];
			for (int i=0;i<len;i++) 
				res[i] = Double.parseDouble(br.readLine());
			br.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}
		return res;
	}
}